package com.healthshare.activity.news;



import com.healthshare.R;
import com.palmedia.framework.ui.CustomMessageShow;

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;

/**
 * 
 * @author Leong_Andrew 企业资讯视图
 */
public class WebViewActivity extends Activity
{
	
	// 加载提示
	private WebView wv;
	
	//ProgressDialog pd;
	
	//Handler handler;
	
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.webview);
		 getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
		wv = (WebView) this.findViewById(R.id.webview);
		
		//((Button)this.findViewById(R.id.backbutton)).setVisibility(View.VISIBLE);
		//((Button)this.findViewById(R.id.backbutton)).setTextColor(Color.rgb(0,139,0));
		
		Bundle bb = this.getIntent().getBundleExtra("bundle");
		String url = bb.getString("url");
		String title = bb.getString("title");
		
		//Button backbutton = (Button) this.findViewById(R.id.backbutton);
		//backbutton.setVisibility(View.VISIBLE);
		
		//TextView titletextview  = (TextView) this.findViewById(R.id.titletextview);

		//titletextview.setText(title);
		TextView favoriteButton = (TextView)findViewById(R.id.favorite); 
		TextView shareButton = (TextView)findViewById(R.id.share); 
		favoriteButton.setVisibility(View.GONE);
		shareButton.setVisibility(View.GONE);
		 TextView titleButton = (TextView)findViewById(R.id.titleButton);  
	        
	        titleButton.setOnClickListener(new OnClickListener() {  
	            @Override  
	            public void onClick(View v) { 
	            	 finish();
	            }  
	        });  
		
		/*handler = new Handler()
		{
			public void handleMessage(Message msg)
			{// 定义一个Handler，用于处理下载线程与UI间通讯
				//if (!Thread.currentThread().isInterrupted())
				{
					switch (msg.what)
					{
						case 0:
							pd.show();// 显示进度对话框
							//CustomMessageShow.getInst().showProgressDialog(WebViewActivity.this);
							break;
						case 1:
							pd.hide();// 隐藏进度对话框，不可使用dismiss()、cancel(),否则再次调用show()时，显示的对话框小圆圈不会动。
							break;
					}
				}
				super.handleMessage(msg);
			}
		};*/
		init();
		loadurl(wv, url);
	}
	
	public void backButtonAction(View v)
	{
		this.finish();
	}
	
	// 初始化
	private void init()
	{
		
		// wv=(WebView)findViewById(R.id.wv);
		WebSettings setting = wv.getSettings();
		//wv.setInitialScale(50);//为25%，最小缩放等级 
		setting.setJavaScriptEnabled(true);// 可用JS
		setting.setSupportZoom(true); // 设置可以支持缩放
		setting.setBuiltInZoomControls(true); // 设置出现缩放工具
		//setting.setTextSize(t)
		//setting.setTextSize(WebSettings.TextSize.LARGEST);
		wv.setScrollBarStyle(0);// 滚动条风格，为0就是不给滚动条留空间，滚动条覆盖在网页上
		
		wv.setWebViewClient(new WebViewClient()
		{
			
			public boolean shouldOverrideUrlLoading(final WebView view,
					final String url)
			{
				
				loadurl(view, url);// 载入网页
				
				return true;
				
			}// 重写点击动作,用webview载入
			
		});
		
		wv.setWebChromeClient(new WebChromeClient()
		{
			public void onProgressChanged(WebView view, int progress)
			{// 载入进度改变而触发
				if (progress == 100)
				{
					//handler.sendEmptyMessage(1);// 如果全部载入,隐藏进度对话框
					CustomMessageShow.getInst().cancleProgressDialog();
				}
				super.onProgressChanged(view, progress);
			}
		});
		//pd = new ProgressDialog(this);
		//pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		//pd.setMessage("数据载入中，请稍候！");
	}
	
	public void loadurl(final WebView view, final String url)
	{
		//handler.sendEmptyMessage(0);
		CustomMessageShow.getInst().showProgressDialog(WebViewActivity.this);
		view.loadUrl(url);// 载入网页
		/*
		new Thread()
		{
			public void run()
			{
				handler.sendEmptyMessage(0);
				view.loadUrl(url);// 载入网页
			}
		}.start();*/
	}
	public boolean onKeyDown(int keyCode, KeyEvent event) 
	{
		 return true;
	 }
}
